package cn.tom.controller;


import cn.hutool.core.date.DateUtil;
import cn.tom.entity.ExportVo;
import cn.tom.service.ExcelService;
import cn.tom.tool.MyExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping({"/excelDow/"})
public class ExcelController {
    @Autowired
    private ExcelService excelService;

    @PostMapping("/exportTest")
    public void export(String[] p1Id, HttpServletResponse response) {
        System.out.println(Arrays.toString(p1Id));
        if (p1Id.length!=0) {
            int[] array = Arrays.asList(p1Id).stream().mapToInt(Integer::parseInt).toArray();
            excelService.exportExcelData(array,response);
        }
    }

   /* @GetMapping("/exportTest")
    public void export(HttpServletResponse response) {
        System.out.println("hhhhhhhhhhhhhhhhhh");
        List<Object> build = build();
        //调用上述封装好的导出方法
        new MyExcelUtil().exportData(build, "data2", response);
    }*/

	//构造一对多嵌套数据
   /* public static List<Object> build() {
        List<Object> exportVos = new ArrayList<>();
        Date date = new Date();
        String formatDate = DateUtil.formatDate(date);
        //第一条数据
        List<ExportVo.ProjectGroupExcelVO> projectGroupList = new ArrayList<>();
        ExportVo.ProjectGroupExcelVO projectGroupExcelVO1 = ExportVo.ProjectGroupExcelVO.builder()
                .name("界面效果程序编写|14")
                .leader("hhh21")
                .startDate(formatDate)
                .estimatedDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)
                .problem("暂无")
                .build();
        ExportVo.ProjectGroupExcelVO projectGroupExcelVO3 = ExportVo.ProjectGroupExcelVO.builder()
                .name("小程序功能代码编写|10")
                .leader("hhh21")
                .startDate(formatDate)
                .estimatedDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)
                .build();

        ExportVo.ProjectGroupExcelVO projectGroupExcelVO2 = ExportVo.ProjectGroupExcelVO.builder()
                .name("小程序功能代码编写|12")
                .leader("hhh21")
                .startDate(formatDate)
                .estimatedDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)
                .build();


        projectGroupList.add(projectGroupExcelVO1);
        projectGroupList.add(projectGroupExcelVO3);
        projectGroupList.add(projectGroupExcelVO2);
        ExportVo exportVo = ExportVo.builder().name1("ZKDM156中置柜电动底盘画及接地开关智能控制器")
                .category("A")
                .name2("电动底盘车控制ＡＰＰ升级")
                .build();
        exportVo.setSteps(projectGroupList);


        //第二条数据
        List<ExportVo.ProjectGroupExcelVO> projectGroupList2 = new ArrayList<>();
        ExportVo.ProjectGroupExcelVO projectGroupExcelVO22 = ExportVo.ProjectGroupExcelVO.builder()
                .name("客户端接口编写|10")
                .leader("hhh22")
                .startDate(formatDate)
                .estimatedDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)
                .build();

        ExportVo.ProjectGroupExcelVO projectGroupExcelVO23 = ExportVo.ProjectGroupExcelVO.builder()
                .name("服务端接口编写|10")
                .leader("hhh22")
                .startDate(formatDate)
                .estimatedDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)
                .build();

        projectGroupList2.add(projectGroupExcelVO22);
        projectGroupList2.add(projectGroupExcelVO23);
        ExportVo exportVo2 = ExportVo.builder().name1("订单系统微信小程序")
                .category("B")
                .name2("订单系统微信小程序改版")
                .build();
        exportVo2.setSteps(projectGroupList2);
        exportVos.add(exportVo);
        exportVos.add(exportVo2);
        return exportVos;
    }*/


}
